import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'screens/home_screen.dart';
import 'screens/account_management_screen.dart';
import 'screens/show_config_screen.dart';
import 'screens/platform_selection_screen.dart';
import 'screens/unified_hunting_screen.dart';
import 'providers/account_provider.dart';
import 'providers/show_provider.dart';
import 'providers/ticket_hunter_provider.dart';
import 'utils/theme.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await SharedPreferences.getInstance();
  runApp(const TicketHunterProApp());
}

class TicketHunterProApp extends StatelessWidget {
  const TicketHunterProApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => AccountProvider()),
        ChangeNotifierProvider(create: (_) => ShowProvider()),
        ChangeNotifierProvider(create: (_) => TicketHunterProvider()),
      ],
      child: MaterialApp(
        title: '抢票利器',
        theme: AppTheme.lightTheme,
        darkTheme: AppTheme.darkTheme,
        themeMode: ThemeMode.system,
        home: const MainNavigator(),
        debugShowCheckedModeBanner: false,
      ),
    );
  }
}

class MainNavigator extends StatefulWidget {
  const MainNavigator({super.key});

  @override
  State<MainNavigator> createState() => _MainNavigatorState();
}

class _MainNavigatorState extends State<MainNavigator> {
  int _currentIndex = 0;

  final List<Widget> _screens = [
    const HomeScreen(),
    const AccountManagementScreen(),
    const ShowConfigScreen(),
    const UnifiedHuntingScreen(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _currentIndex,
        children: _screens,
      ),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: _currentIndex,
        onTap: (index) => setState(() => _currentIndex = index),
        items: const [
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            label: '首页',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.account_circle),
            label: '账号管理',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.music_note),
            label: '演出配置',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.flash_on),
            label: '抢票',
          ),
        ],
      ),
    );
  }
}